home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Produtividade / Software2 / Product4 / Setup.exe / drupal-4.6.0 / includes / theme.inc < prev    next >
Encoding:
Text File  |  2005-04-13  |  26.2 KB  |  952 lines

  1. <?php
  2. /* $Id: theme.inc,v 1.228.2.1 2005/04/13 18:00:03 dries Exp $ */
  3.  
  4. /**
  5.  * @file
  6.  * The theme system, which controls the output of Drupal.
  7.  *
  8.  * The theme system allows for nearly all output of the Drupal system to be
  9.  * customized by user themes.
  10.  *
  11.  * @see <a href="http://drupal.org/node/253">Theme system</a>
  12.  * @see themeable
  13.  */
  14.  
  15.  /**
  16.  * @name Content markers
  17.  * @{
  18.  * Markers used by theme_mark() and node_mark() to designate content.
  19.  * @see theme_mark(), node_mark()
  20.  */
  21. define('MARK_READ',    0);
  22. define('MARK_NEW',     1);
  23. define('MARK_UPDATED', 2);
  24. /**
  25.  * @} End of "Content markers".
  26.  */
  27.  
  28. /**
  29.  * Hook Help - returns theme specific help and information.
  30.  *
  31.  * @param section defines the @a section of the help to be returned.
  32.  *
  33.  * @return a string containing the help output.
  34.  */
  35. function theme_help($section) {
  36.   switch ($section) {
  37.     case 'admin/themes#description':
  38.       return t('The base theme');
  39.   }
  40. }
  41.  
  42. /**
  43.  * Initialize the theme system by loading the theme.
  44.  *
  45.  * @return
  46.  *   The name of the currently selected theme.
  47.  */
  48. function init_theme() {
  49.   global $user, $custom_theme, $theme_engine, $theme_key;
  50.  
  51.   $themes = list_themes();
  52.  
  53.   // Only select the user selected theme if it is available in the
  54.   // list of enabled themes.
  55.   $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'bluemarine');
  56.  
  57.   // Allow modules to override the present theme... only select custom theme
  58.   // if it is available in the list of installed themes.
  59.   $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
  60.  
  61.   // Store the identifier for retrieving theme settings with.
  62.   $theme_key = $theme;
  63.  
  64.   // If we're using a style, load its appropriate theme,
  65.   // which is stored in the style's description field.
  66.   // Also load the stylesheet using drupal_set_html_head().
  67.   // Otherwise, load the theme.
  68.   if (strpos($themes[$theme]->filename, '.css')) {
  69.     // File is a style; loads its CSS.
  70.     // Set theme to its template/theme
  71.     theme_add_style($themes[$theme]->filename);
  72.     $theme = basename(dirname($themes[$theme]->description));
  73.   }
  74.   else {
  75.     // File is a template/theme
  76.     // Load its CSS, if it exists
  77.     if (file_exists($stylesheet = dirname($themes[$theme]->filename) .'/style.css')) {
  78.       theme_add_style($stylesheet);
  79.     }
  80.   }
  81.  
  82.   if (strpos($themes[$theme]->filename, '.theme')) {
  83.     // file is a theme; include it
  84.     include_once($themes[$theme]->filename);
  85.   }
  86.   elseif (strpos($themes[$theme]->description, '.engine')) {
  87.     // file is a template; include its engine
  88.     include_once($themes[$theme]->description);
  89.     $theme_engine = basename($themes[$theme]->description, '.engine');
  90.     if (function_exists($theme_engine .'_init')) {
  91.       call_user_func($theme_engine .'_init', $themes[$theme]);
  92.     }
  93.   }
  94.  
  95.   return $theme;
  96. }
  97.  
  98. /**
  99.  * Provides a list of currently available themes.
  100.  *
  101.  * @param $refresh
  102.  *   Whether to reload the list of themes from the database.
  103.  * @return
  104.  *   An array of the currently available themes.
  105.  */
  106. function list_themes($refresh = FALSE) {
  107.   static $list;
  108.  
  109.   if ($refresh) {
  110.     unset($list);
  111.   }
  112.  
  113.   if (!$list) {
  114.     $list = array();
  115.     $result = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name");
  116.     while ($theme = db_fetch_object($result)) {
  117.       if (file_exists($theme->filename)) {
  118.         $list[$theme->name] = $theme;
  119.       }
  120.     }
  121.   }
  122.  
  123.   return $list;
  124. }
  125.  
  126. /**
  127.  * Provides a list of currently available theme engines
  128.  *
  129.  * @param $refresh
  130.  *   Whether to reload the list of themes from the database.
  131.  * @return
  132.  *   An array of the currently available theme engines.
  133.  */
  134. function list_theme_engines($refresh = FALSE) {
  135.   static $list;
  136.  
  137.   if ($refresh) {
  138.     unset($list);
  139.   }
  140.  
  141.   if (!$list) {
  142.     $list = array();
  143.     $result = db_query("SELECT * FROM {system} WHERE type = 'theme_engine' AND status = '1' ORDER BY name");
  144.     while ($engine = db_fetch_object($result)) {
  145.       if (file_exists($engine->filename)) {
  146.         $list[$engine->name] = $engine;
  147.       }
  148.     }
  149.   }
  150.  
  151.   return $list;
  152. }
  153.  
  154. /**
  155.  * Generate the themed representation of a Drupal object.
  156.  *
  157.  * All requests for themed functions must go through this function. It examines
  158.  * the request and routes it to the appropriate theme function. If the current
  159.  * theme does not implement the requested function, then the current theme
  160.  * engine is checked. If neither the engine nor theme implement the requested
  161.  * function, then the base theme function is called.
  162.  *
  163.  * For example, to retrieve the HTML that is output by theme_page($output), a
  164.  * module should call theme('page', $output).
  165.  *
  166.  * @param $function
  167.  *   The name of the theme function to call.
  168.  * @param ...
  169.  *   Additional arguments to pass along to the theme function.
  170.  * @return
  171.  *   An HTML string that generates the themed output.
  172.  */
  173. function theme() {
  174.   global $theme, $theme_engine;
  175.  
  176.   if (!$theme) {
  177.     // Initialize the enabled theme.
  178.     $theme = init_theme();
  179.   }
  180.  
  181.   $args = func_get_args();
  182.   $function = array_shift($args);
  183.  
  184.   if (($theme != '') && function_exists($theme .'_'. $function)) {
  185.     // call theme function
  186.     return call_user_func_array($theme .'_'. $function, $args);
  187.   }
  188.   elseif (($theme != '') && isset($theme_engine) && function_exists($theme_engine .'_'. $function)) {
  189.     // call engine function
  190.     return call_user_func_array($theme_engine .'_'. $function, $args);
  191.   }
  192.   elseif (function_exists('theme_'. $function)){
  193.     // call Drupal function
  194.     return call_user_func_array('theme_'. $function, $args);
  195.   }
  196. }
  197.  
  198. /**
  199.  * Return the path to the currently selected theme.
  200.  */
  201. function path_to_theme() {
  202.   global $theme;
  203.  
  204.   $themes = list_themes();
  205.  
  206.   return dirname($themes[$theme]->filename);
  207. }
  208.  
  209. /**
  210.  * Retrieve an associative array containing the settings for a theme.
  211.  *
  212.  * The final settings are arrived at by merging the default settings,
  213.  * the site-wide settings, and the settings defined for the specific theme.
  214.  * If no $key was specified, only the site-wide theme defaults are retrieved.
  215.  *
  216.  * The default values for each of settings are also defined in this function.
  217.  * To add new settings, add their default values here, and then add form elements
  218.  * to system_theme_settings() in system.module.
  219.  *
  220.  * @param $key
  221.  *  The template/style value for a given theme.
  222.  *
  223.  * @return
  224.  *   An associative array containing theme settings.
  225.  */
  226. function theme_get_settings($key = NULL) {
  227.   $defaults = array(
  228.     'primary_links'                 =>  l(t('edit primary links'), 'admin/themes/settings'),
  229.     'secondary_links'               =>  l(t('edit secondary links'), 'admin/themes/settings'),
  230.     'mission'                       =>  '',
  231.     'default_logo'                  =>  1,
  232.     'logo_path'                     =>  '',
  233.     'toggle_logo'                   =>  1,
  234.     'toggle_name'                   =>  1,
  235.     'toggle_search'                 =>  1,
  236.     'toggle_slogan'                 =>  0,
  237.     'toggle_mission'                =>  1,
  238.     'toggle_primary_links'          =>  1,
  239.     'toggle_secondary_links'        =>  1,
  240.     'toggle_node_user_picture'      =>  0,
  241.     'toggle_comment_user_picture'   =>  0,
  242.   );
  243.  
  244.   if (module_exist('node')) {
  245.     foreach (node_list() as $type) {
  246.       $defaults['toggle_node_info_' . $type] = 1;
  247.     }
  248.   }
  249.   $settings = array_merge($defaults, variable_get('theme_settings', array()));
  250.  
  251.   if ($key) {
  252.     $settings = array_merge($settings, variable_get(str_replace('/', '_', 'theme_'. $key .'_settings'), array()));
  253.   }
  254.  
  255.   // Only offer search box if search.module is enabled.
  256.   if (!module_exist('search')) {
  257.     $settings['toggle_search'] = 0;
  258.   }
  259.  
  260.   return $settings;
  261. }
  262.  
  263. /**
  264.  * Retrieve a setting for the current theme.
  265.  * This function is designed for use from within themes & engines
  266.  * to determine theme settings made in the admin interface.
  267.  *
  268.  * Caches values for speed (use $refresh = TRUE to refresh cache)
  269.  *
  270.  * @param $setting_name
  271.  *  The name of the setting to be retrieved.
  272.  *
  273.  * @param $refresh
  274.  *  Whether to reload the cache of settings.
  275.  *
  276.  * @return
  277.  *   The value of the requested setting, NULL if the setting does not exist.
  278.  */
  279. function theme_get_setting($setting_name, $refresh = FALSE) {
  280.   global $theme_key;
  281.   static $settings;
  282.  
  283.   if (empty($settings) || $refresh) {
  284.     $settings = theme_get_settings($theme_key);
  285.  
  286.     $themes = list_themes();
  287.     $theme_object = $themes[$theme_key];
  288.  
  289.     if ($settings['mission'] == '') {
  290.       $settings['mission'] = variable_get('site_mission', '');
  291.     }
  292.  
  293.     if (!$settings['toggle_mission']) {
  294.       $settings['mission'] = '';
  295.     }
  296.  
  297.     if ($settings['toggle_logo']) {
  298.       if ($settings['default_logo']) {
  299.         $settings['logo'] = dirname($theme_object->filename) .'/logo.png';
  300.       }
  301.       elseif ($settings['logo_path']) {
  302.         $settings['logo'] = $settings['logo_path'];
  303.       }
  304.     }
  305.  
  306.     if (!$settings['toggle_primary_links']) {
  307.       $settings['primary_links'] = '';
  308.     }
  309.  
  310.     if (!$settings['toggle_secondary_links']) {
  311.       $settings['secondary_links'] = '';
  312.     }
  313.   }
  314.  
  315.   return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
  316. }
  317.  
  318. /**
  319.  * Add a theme stylesheet to be included later. This is handled separately from
  320.  * drupal_set_html_head() to enforce the correct CSS cascading order.
  321.  */
  322. function theme_add_style($style = '') {
  323.   static $styles = array();
  324.   if ($style) {
  325.     $styles[] = $style;
  326.   }
  327.   return $styles;
  328. }
  329.  
  330. /**
  331.  * Return the HTML for a theme's stylesheets.
  332.  */
  333. function theme_get_styles() {
  334.   $output = '';
  335.   foreach (theme_add_style() as $style) {
  336.     $output .= theme('stylesheet_import', $style);
  337.   }
  338.   return $output;
  339. }
  340.  
  341. /**
  342.  * @defgroup themeable Themeable functions
  343.  * @{
  344.  * Functions that display HTML, and which can be customized by themes.
  345.  *
  346.  * All functions that produce HTML for display should be themeable. This means
  347.  * that they should be named with the theme_ prefix, and invoked using theme()
  348.  * rather than being called directly. This allows themes to override the display
  349.  * of any Drupal object.
  350.  *
  351.  * The theme system is described and defined in theme.inc.
  352.  */
  353.  
  354. /**
  355.  * Format a dynamic text string for emphasised display in a placeholder.
  356.  *
  357.  * E.g. t('Added term %term', array('%term' => theme('placeholder', $term)))
  358.  *
  359.  * @param $text
  360.  *   The text to format (plain-text).
  361.  * @return
  362.  *   The formatted text (html).
  363.  */
  364. function theme_placeholder($text) {
  365.   return '<em>'. check_plain($text) .'</em>';
  366. }
  367.  
  368. /**
  369.  * Return an entire Drupal page displaying the supplied content.
  370.  *
  371.  * @param $content
  372.  *   A string to display in the main content area of the page.
  373.  * @return
  374.  *   A string containing the entire HTML page.
  375.  */
  376. function theme_page($content) {
  377.   $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
  378.   $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
  379.   $output .= '<head>';
  380.   $output .= ' <title>'. (drupal_get_title() ? strip_tags(drupal_get_title()) : variable_get('site_name', 'drupal')) .'</title>';
  381.   $output .= drupal_get_html_head();
  382.   $output .= theme_get_styles();
  383.  
  384.   $output .= ' </head>';
  385.   $output .= ' <body style="background-color: #fff; color: #000;"'. theme('onload_attribute'). '">';
  386.   $output .= '<table border="0" cellspacing="4" cellpadding="4"><tr><td style="vertical-align: top; width: 170px;">';
  387.  
  388.   $output .= theme('blocks', 'all');
  389.   $output .= '</td><td style="vertical-align: top;">';
  390.  
  391.   $output .= theme('breadcrumb', drupal_get_breadcrumb());
  392.   $output .= '<h1>' . drupal_get_title() . '</h1>';
  393.  
  394.   if ($tabs = theme('menu_local_tasks')) {
  395.    $output .= $tabs;
  396.   }
  397.  
  398.   if ($help = menu_get_active_help()) {
  399.     $output .= '<small>'. $help .'</small><hr />';
  400.   }
  401.  
  402.   $output .= theme_status_messages();
  403.  
  404.   $output .= "\n<!-- begin content -->\n";
  405.   $output .= $content;
  406.   $output .= "\n<!-- end content -->\n";
  407.  
  408.   $output .= '</td></tr></table>';
  409.   $output .= theme_closure();
  410.   $output .= '</body></html>';
  411.  
  412.   return $output;
  413. }
  414.  
  415. /**
  416.  * Returns themed set of status and/or error messages.  The messages are grouped
  417.  * by type.
  418.  *
  419.  * @return
  420.  *   A string containing the messages.
  421.  */
  422. function theme_status_messages() {
  423.   if ($data = drupal_get_messages()) {
  424.     $output = '';
  425.     foreach ($data as $type => $messages) {
  426.       $output .= "<div class=\"messages $type\">\n";
  427.       if (count($messages) > 1) {
  428.         $output .= " <ul>\n";
  429.         foreach($messages as $message) {
  430.           $output .= '  <li>'. $message ."</li>\n";
  431.         }
  432.         $output .= " </ul>\n";
  433.       }
  434.       else {
  435.         $output .= $messages[0];
  436.       }
  437.       $output .= "</div>\n";
  438.     }
  439.  
  440.     return $output;
  441.   }
  442. }
  443.  
  444. /**
  445.  * Return a themed set of links.
  446.  *
  447.  * @param $links
  448.  *   An array of links to be themed.
  449.  * @param $delimiter
  450.  *   A string used to separate the links.
  451.  * @return
  452.  *   A string containing the themed links.
  453.  */
  454. function theme_links($links, $delimiter = ' | ') {
  455.   return implode($delimiter, $links);
  456. }
  457.  
  458. /**
  459.  * Return a themed image.
  460.  *
  461.  * @param $path
  462.  *   The path of the image file.
  463.  * @param $alt
  464.  *   The alternative text for text-based browsers.
  465.  * @param $title
  466.  *   The title text is displayed when the image is hovered in some popular browsers.
  467.  * @param $attr
  468.  *   Attributes placed in the img tag.
  469.  * @param $getsize
  470.  *   If set to true, the image's dimension are fetched and added as width/height attributes.
  471.  * @return
  472.  *   A string containing the image tag.
  473.  */
  474. function theme_image($path, $alt = '', $title = '', $attr = '', $getsize = true) {
  475.   if (!$getsize || (file_exists($path) && (list($width, $height, $type, $attr) = @getimagesize($path)))) {
  476.     return "<img src=\"$path\" $attr alt=\"$alt\" title=\"$title\" />";
  477.   }
  478. }
  479.  
  480. /**
  481.  * Return a themed breadcrumb trail.
  482.  *
  483.  * @param $breadcrumb
  484.  *   An array containing the breadcrumb links.
  485.  * @return a string containing the breadcrumb output.
  486.  */
  487. function theme_breadcrumb($breadcrumb) {
  488.   return '<div class="breadcrumb">'. implode($breadcrumb, ' » ') .'</div>';
  489. }
  490.  
  491. /**
  492.  * Return a themed node.
  493.  *
  494.  * @param $node
  495.  *   An object providing all relevant information for displaying a node:
  496.  *   - $node->nid: The ID of the node.
  497.  *   - $node->type: The content type (story, blog, forum...).
  498.  *   - $node->title: The title of the node.
  499.  *   - $node->created: The creation date, as a UNIX timestamp.
  500.  *   - $node->teaser: A shortened version of the node body.
  501.  *   - $node->body: The entire node contents.
  502.  *   - $node->changed: The last modification date, as a UNIX timestamp.
  503.  *   - $node->uid: The ID of the author.
  504.  *   - $node->username: The username of the author.
  505.  * @param $teaser
  506.  *   Whether to display the teaser only, as on the main page.
  507.  * @param $page
  508.  *   Whether to display the node as a standalone page. If TRUE, do not display
  509.  *   the title because it will be provided by the menu system.
  510.  * @return
  511.  *   A string containing the node output.
  512.  */
  513. function theme_node($node, $teaser = FALSE, $page = FALSE) {
  514.   if (module_exist('taxonomy')) {
  515.     $terms = taxonomy_link('taxonomy terms', $node);
  516.   }
  517.  
  518.   if ($page == 0) {
  519.     $output = '<h2 class="title">'. check_plain($node->title) .'</h2> by '. format_name($node);
  520.   }
  521.   else {
  522.     $output = 'by '. format_name($node);
  523.   }
  524.  
  525.   if (count($terms)) {
  526.     $output .= ' <small>('. theme('links', $terms) .')</small><br />';
  527.   }
  528.  
  529.   if ($teaser && $node->teaser) {
  530.     $output .= $node->teaser;
  531.   }
  532.   else {
  533.     $output .= $node->body;
  534.   }
  535.  
  536.   if ($node->links) {
  537.     $output .= '<div class="links">'. theme('links', $node->links) .'</div>';
  538.   }
  539.  
  540.   return $output;
  541. }
  542.  
  543. /**
  544.  * Return a themed form element.
  545.  *
  546.  * @param $title the form element's title
  547.  * @param $value the form element's data
  548.  * @param $description the form element's description or explanation
  549.  * @param $id the form element's ID used by the <label> tag
  550.  * @param $required a boolean to indicate whether this is a required field or not
  551.  * @param $error a string with an error message filed against this form element
  552.  *
  553.  * @return a string representing the form element
  554.  */
  555. function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
  556.  
  557.   $output  = "<div class=\"form-item\">\n";
  558.   $required = $required ? '<span class="form-required">*</span>' : '';
  559.  
  560.   if ($title) {
  561.     if ($id) {
  562.       $output .= " <label for=\"$id\">$title:</label>$required<br />\n";
  563.     }
  564.     else {
  565.       $output .= " <label>$title:</label>$required<br />\n";
  566.     }
  567.   }
  568.  
  569.   $output .= " $value\n";
  570.  
  571.   if ($description) {
  572.     $output .= " <div class=\"description\">$description</div>\n";
  573.   }
  574.  
  575.   $output .= "</div>\n";
  576.  
  577.   return $output;
  578. }
  579.  
  580.  
  581. /**
  582.  * Return a themed submenu, typically displayed under the tabs.
  583.  *
  584.  * @param $links
  585.  *   An array of links.
  586.  */
  587. function theme_submenu($links) {
  588.   return '<div class="submenu">'. implode(' | ', $links) .'</div>';
  589. }
  590.  
  591. /**
  592.  * Return a themed table.
  593.  *
  594.  * @param $header
  595.  *   An array containing the table headers. Each element of the array can be
  596.  *   either a localized string or an associative array with the following keys:
  597.  *   - "data": The localized title of the table column.
  598.  *   - "field": The database field represented in the table column (required if
  599.  *     user is to be able to sort on this column).
  600.  *   - "sort": A default sort order for this column ("asc" or "desc").
  601.  *   - Any HTML attributes, such as "colspan", to apply to the column header cell.
  602.  * @param $rows
  603.  *   An array of table rows. Every row is an array of cells, or an associative
  604.  *   array with the following keys:
  605.  *   - "data": an array of cells
  606.  *   - Any HTML attributes, such as "class", to apply to the table row.
  607.  *
  608.  *   Each cell can be either a string or an associative array with the following keys:
  609.  *   - "data": The string to display in the table cell.
  610.  *   - Any HTML attributes, such as "colspan", to apply to the table cell.
  611.  *
  612.  *   Here's an example for $rows:
  613.  *   @verbatim
  614.  *   $rows = array(
  615.  *     // Simple row
  616.  *     array(
  617.  *       'Cell 1', 'Cell 2', 'Cell 3'
  618.  *     ),
  619.  *     // Row with attributes on the row and some of its cells.
  620.  *     array(
  621.  *       'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky'
  622.  *     )
  623.  *   );
  624.  *   @endverbatim
  625.  *
  626.  * @param $attributes
  627.  *   An array of HTML attributes to apply to the table tag.
  628.  * @return
  629.  *   An HTML string representing the table.
  630.  */
  631. function theme_table($header, $rows, $attributes = NULL) {
  632.  
  633.   $output = '<table'. drupal_attributes($attributes) .">\n";
  634.  
  635.   // Format the table header:
  636.   if (is_array($header)) {
  637.     $ts = tablesort_init($header);
  638.     $output .= ' <tr>';
  639.     foreach ($header as $cell) {
  640.       $cell = tablesort_header($cell, $header, $ts);
  641.       $output .= _theme_table_cell($cell, 1);
  642.     }
  643.     $output .= " </tr>\n";
  644.   }
  645.  
  646.   // Format the table rows:
  647.   if (is_array($rows)) {
  648.     foreach ($rows as $number => $row) {
  649.       $attributes = array();
  650.  
  651.       // Check if we're dealing with a simple or complex row
  652.       if (isset($row['data'])) {
  653.         foreach ($row as $key => $value) {
  654.           if ($key == 'data') {
  655.             $cells = $value;
  656.           }
  657.           else {
  658.             $attributes[$key] = $value;
  659.           }
  660.         }
  661.       }
  662.       else {
  663.         $cells = $row;
  664.       }
  665.  
  666.       // Add light/dark class
  667.       $class = ($number % 2 == 1) ? 'light': 'dark';
  668.       if (isset($attributes['class'])) {
  669.         $attributes['class'] .= ' '. $class;
  670.       }
  671.       else {
  672.         $attributes['class'] = $class;
  673.       }
  674.  
  675.       // Build row
  676.       $output .= ' <tr'. drupal_attributes($attributes) .'>';
  677.       $i = 0;
  678.       foreach ($cells as $cell) {
  679.         $cell = tablesort_cell($cell, $header, $ts, $i++);
  680.         $output .= _theme_table_cell($cell, 0);
  681.       }
  682.       $output .= " </tr>\n";
  683.     }
  684.   }
  685.  
  686.   $output .= "</table>\n";
  687.   return $output;
  688. }
  689.  
  690. /**
  691.  * Return a themed box.
  692.  *
  693.  * @param $title
  694.  *   The subject of the box.
  695.  * @param $content
  696.  *   The content of the box.
  697.  * @param $region
  698.  *   The region in which the box is displayed.
  699.  * @return
  700.  *   A string containing the box output.
  701.  */
  702. function theme_box($title, $content, $region = 'main') {
  703.   $output = '<h2 class="title">'. $title .'</h2><div>'. $content .'</div>';
  704.   return $output;
  705. }
  706.  
  707. /**
  708.  * Return a themed block.
  709.  *
  710.  * You can style your blocks by defining .block (all blocks),
  711.  * .block-<i>module</i> (all blocks of module <i>module</i>), and
  712.  * \#block-<i>module</i>-<i>delta</i> (specific block of module <i>module</i>
  713.  * with delta <i>delta</i>) in your theme's CSS.
  714.  *
  715.  * @param $block
  716.  *   An object populated with fields from the "blocks" database table
  717.  *   ($block->module, $block->delta, $block->region, ...) and fields returned by
  718.  *   <i>module</i>_block('view') ($block->subject, $block->content, ...).
  719.  * @return
  720.  *   A string containing the block output.
  721.  */
  722. function theme_block($block) {
  723.   $output  = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
  724.   $output .= " <h2 class=\"title\">$block->subject</h2>\n";
  725.   $output .= " <div class=\"content\">$block->content</div>\n";
  726.   $output .= "</div>\n";
  727.   return $output;
  728. }
  729.  
  730. /**
  731.  * Return a themed marker, useful for marking new or updated
  732.  * content.
  733.  *
  734.  * @param $type
  735.  *   Number representing the marker type to display
  736.  * @see MARK_NEW, MARK_UPDATED, MARK_READ
  737.  * @return
  738.  *   A string containing the marker.
  739.  */
  740. function theme_mark($type = MARK_NEW) {
  741.   global $user;
  742.   if ($user->uid && $type != MARK_READ) {
  743.     return '<span class="marker">*</span>';
  744.   }
  745. }
  746.  
  747. /**
  748.  * Import a stylesheet using @import.
  749.  *
  750.  * @param $stylesheet
  751.  *  The filename to point the link at.
  752.  *
  753.  * @param $media
  754.  *  The media type to specify for the stylesheet
  755.  *
  756.  * @return
  757.  *  A string containing the HTML for the stylesheet import.
  758.  */
  759. function theme_stylesheet_import($stylesheet, $media = 'all') {
  760.   return '<style type="text/css" media="'. $media .'">@import "'. $stylesheet .'";</style>';
  761. }
  762.  
  763. /**
  764.  * Return a themed list of items.
  765.  *
  766.  * @param $items
  767.  *   An array of items to be displayed in the list.
  768.  * @param $title
  769.  *   The title of the list.
  770.  * @return
  771.  *   A string containing the list output.
  772.  */
  773. function theme_item_list($items = array(), $title = NULL) {
  774.   $output = '<div class="item-list">';
  775.   if (isset($title)) {
  776.     $output .= '<h3>'. $title .'</h3>';
  777.   }
  778.  
  779.   if (isset($items)) {
  780.     $output .= '<ul>';
  781.     foreach ($items as $item) {
  782.       $output .= '<li>'. $item .'</li>';
  783.     }
  784.     $output .= '</ul>';
  785.   }
  786.   $output .= '</div>';
  787.   return $output;
  788. }
  789.  
  790. /**
  791.  * Return a themed error message.
  792.  * REMOVE: this function is deprecated an no longer used in core.
  793.  *
  794.  * @param $message
  795.  *   The error message to be themed.
  796.  *
  797.  * @return
  798.  *   A string containing the error output.
  799.  */
  800. function theme_error($message) {
  801.   return '<div class="error">'. $message .'</div>';
  802. }
  803.  
  804. function theme_more_help_link($url) {
  805.   return '<div class="more-help-link">' . t('[<a href="%link">more help...</a>]', array('%link' => $url)) . '</div>';
  806. }
  807.  
  808. /**
  809.  * Return code that emits an XML icon.
  810.  */
  811. function theme_xml_icon($url) {
  812.   if ($image = theme('image', 'misc/xml.png', t('XML feed'), t('XML feed'))) {
  813.     return '<div class="xml-icon"><a href="'. $url .'">'. $image. '</a></div>';
  814.   }
  815. }
  816.  
  817. /**
  818.  * Execute hook_footer() which is run at the end of the page right before the
  819.  * close of the body tag.
  820.  *
  821.  * @param $main (optional)
  822.  *
  823.  * @return
  824.  *   A string containing the results of the hook_footer() calls.
  825.  */
  826. function theme_closure($main = 0) {
  827.   $footer = module_invoke_all('footer', $main);
  828.   return implode($footer, "\n");
  829. }
  830.  
  831. /**
  832.  * Call hook_onload() in all modules to enable modules to insert JavaScript that
  833.  * will get run once the page has been loaded by the browser.
  834.  *
  835.  * @param $theme_onloads
  836.  *   Additional onload directives.
  837.  * @return
  838.  *   A string containing the onload attributes.
  839.  */
  840. function theme_onload_attribute($theme_onloads = array()) {
  841.   if (!is_array($theme_onloads)) {
  842.     $theme_onloads = array($theme_onloads);
  843.   }
  844.   // Merge theme onloads (javascript rollovers, image preloads, etc.)
  845.   // with module onloads (htmlarea, etc.)
  846.   $onloads = array_merge(module_invoke_all('onload'), $theme_onloads);
  847.   if (count($onloads)) {
  848.     return ' onload="' . implode('; ', $onloads) . '"';
  849.   }
  850.   return '';
  851. }
  852.  
  853. /**
  854.  * Return a set of blocks available for the current user.
  855.  *
  856.  * @param $region
  857.  *   Which set of blocks to retrieve.
  858.  * @return
  859.  *   A string containing the themed blocks for this region.
  860.  */
  861. function theme_blocks($region) {
  862.   $output = '';
  863.  
  864.   if ($list = module_invoke('block', 'list', $region)) {
  865.     foreach ($list as $key => $block) {
  866.       // $key == <i>module</i>_<i>delta</i>
  867.       $output .= theme('block', $block);
  868.     }
  869.   }
  870.   return $output;
  871. }
  872.  
  873. /**
  874.  * Output a confirmation form
  875.  *
  876.  * This function outputs a complete form for confirming an action. A link is
  877.  * offered to go back to the item that is being changed in case the user changes
  878.  * his/her mind.
  879.  *
  880.  * You should use $_POST['edit'][$name] (where $name is usually 'confirm') to
  881.  * check if the confirmation was successful.
  882.  *
  883.  * @param $question
  884.  *   The question to ask the user (e.g. "Are you sure you want to delete the
  885.  *   block <em>foo</em>?").
  886.  * @param $path
  887.  *   The page to go to if the user denies the action.
  888.  * @param $description
  889.  *   Additional text to display (defaults to "This action cannot be undone.").
  890.  * @param $yes
  891.  *   A caption for the button which confirms the action (e.g. "Delete",
  892.  *   "Replace", ...).
  893.  * @param $no
  894.  *   A caption for the link which denies the action (e.g. "Cancel").
  895.  * @param $extra
  896.  *   Additional HTML to inject into the form, for example form_hidden()s.
  897.  * @param $name
  898.  *   The internal name used to refer to the confirmation item.
  899.  * @return
  900.  *   A themed HTML string representing the form.
  901.  */
  902. function theme_confirm($question, $path, $description = NULL, $yes = NULL, $no = NULL, $extra = NULL, $name = 'confirm') {
  903.   drupal_set_title($question);
  904.  
  905.   if (is_null($description)) {
  906.     $description = t('This action cannot be undone.');
  907.   }
  908.  
  909.   $output .= '<p>'. $description ."</p>\n";
  910.   if (!is_null($extra)) {
  911.     $output .= $extra;
  912.   }
  913.   $output .= '<div class="container-inline">';
  914.   $output .= form_submit($yes ? $yes : t('Confirm'));
  915.   $output .= l($no ? $no : t('Cancel'), $path);
  916.   $output .= "</div>\n";
  917.  
  918.   $output .= form_hidden($name, 1);
  919.   return form($output, 'post', NULL, array('class' => 'confirmation'));
  920. }
  921.  
  922.  
  923. /**
  924.  * @} End of "defgroup themeable".
  925.  */
  926.  
  927. function _theme_table_cell($cell, $header = 0) {
  928.   $attributes = '';
  929.  
  930.   if (is_array($cell)) {
  931.     $data = $cell['data'];
  932.     foreach ($cell as $key => $value) {
  933.       if ($key != 'data')  {
  934.         $attributes .= " $key=\"$value\"";
  935.       }
  936.     }
  937.   }
  938.   else {
  939.     $data = $cell;
  940.   }
  941.  
  942.   if ($header) {
  943.     $output = "<th$attributes>$data</th>";
  944.   }
  945.   else {
  946.     $output = "<td$attributes>$data</td>";
  947.   }
  948.  
  949.   return $output;
  950. }
  951. ?>
  952.